package com.avengers.mobile.layer.hibernate;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;



public class HibernateGenericDAOImpl extends HibernateDaoSupport implements HibernateGenericDAO {

	static Logger logger = Logger.getLogger("JpaBaseDAOImpl");


	public <T> void save(T entity) throws DataAccessException{
		super.getHibernateTemplate().persist(entity);
	}

	public <T> T update(T entity) throws DataAccessException {
		return (T) super.getHibernateTemplate().merge(entity);
	}

	public <T> void delete(T entity) throws DataAccessException {		
					
		super.getHibernateTemplate().delete(entity);
	}
	
	@SuppressWarnings("unchecked")
	public <T> List<T> find(String queryString) throws DataAccessException {				
		return (List<T>) super.getHibernateTemplate().find(queryString);
	}

	@SuppressWarnings(value = "unchecked")
	public <T> List<T> find(String queryString, Object[] params) {		
		return (List<T>) super.getHibernateTemplate().find(queryString, params);
		
	}

	@SuppressWarnings(value = "unchecked")
	public <T> T findUniqueResult(String queryString) {
		return (T) findUniqueResult(queryString);
	}   

	@SuppressWarnings("unchecked")
	public <T> T findUniqueResult(String queryString, Object[] params) {			
		return (T) DataAccessUtils.uniqueResult(super.getHibernateTemplate().find(queryString, params));
	}

	@SuppressWarnings("unchecked")
	public <T> T findUniqueResult(String queryString,String usuario, String password) {			
		return (T) DataAccessUtils.uniqueResult(super.getHibernateTemplate().find(queryString, usuario, password));
	}
	

	
}